<template>
	<vp-dialog ref="editDialogRef" :span="1">
		<template #title>
			<vp-label zh="新增" en="Add"/>
		</template>
		<el-form label-suffix=":" v-loading="loading"  :model="formData" :rules="formRules" ref="formRef"
			label-width="120px">
			<el-row>
				<vp-col :span="1">
					<el-form-item prop="jx">
						<template #label><vp-label zh="机型" en="A/C Type"/></template>
						<VpAircraftTypeSelect  :selectedId="formData.jx" @selected="(obj:any) =>{formData.jx = obj.jx}" style="width:100%">
						</VpAircraftTypeSelect>
					</el-form-item>
				</vp-col>
			</el-row>
		</el-form>
		<template #footer>
			<vp-btn-confirm :loading="saveLoading" @click="handleSave" />
		</template>
	</vp-dialog>
</template>
<script lang="ts">
import {
  defineComponent,
  onMounted,
  reactive,
  ref,
  toRefs
} from 'vue';
import VpAircraftTypeSelect from '/@/components/vp/aircraftType/VpAircraftTypeSelect.vue';
import validateUtils from '/@/utils/validateUtils';

export default defineComponent({
	name: "editjx",
	emits: ["formSubmited"],
	components: {
		VpAircraftTypeSelect
	},
	setup(props, context) {
		const state = reactive({
			formData: {
				jx:"",
			},
			formRules: {
				jx: [
					validateUtils.notNull
				]
			},
			type: 'add',
			loading: false,
			saveLoading: false,
		});
		const editDialogRef = ref();
		const formRef = ref();
		onMounted(() => {

		})

		const initFormData = () => {
			state.formData = {
				jx: "",
			}
		}

		const handleOpen = () => {
			initFormData();
			initFormData();
			editDialogRef.value.handleOpen();
		};

		// 保存岗位信息
		const handleSave = () => {
			if (state.loading) {
				return;
			}
			state.saveLoading = true;
			formRef.value.validate((valid: Boolean) => {
				if (valid) {
					state.saveLoading = false;
					context.emit("formSubmited", state.formData.jx);
					editDialogRef.value.handleClose();
				} else {
					state.saveLoading = false;
				}
			})
		}
		return {
			...toRefs(state),
			editDialogRef,
			formRef,
			handleOpen,
			handleSave,
			initFormData
		}
	},
})
</script>
